package com.ruoyi.aitwsk.service;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import cn.hutool.core.date.DateTime;

@Service
public class WSKService {
	public String getDate1(String date) {
		return date;
	}
	public String getDate2() {
//		return DateTime.now().toDateStr();
		
		return "2022-11-30";
	}
	
	public List<Map<String,Object>> transPray(JSONArray datas){
		if(datas==null||datas.size()==0)
			return null;
		List<Map<String,Object>> retlist=new ArrayList<Map<String,Object>>();
		for(Object obj : datas) {
			JSONObject item=(JSONObject)obj;
			JSONObject doc=item.getJSONObject("parentvo");
			JSONArray lines=item.getJSONArray("childrenvo");
			
			for(Object lineobj : lines) {
				JSONObject line=(JSONObject)lineobj;
				Map<String,Object> retitem=new LinkedHashMap<String,Object>();
				
				retitem.put("vpraycode", doc.get("vpraycode"));
				retitem.put("crowno", line.get("crowno"));
				String key=doc.getString("vpraycode")+"-"+line.getString("crowno");
				retitem.put("pkey", key);
				retitem.put("coperator", doc.get("operator_code"));
				retitem.put("pk_corp", doc.get("pk_corp"));
				retitem.put("cmangid", line.get("inv_code"));
				retitem.put("npraynum", line.get("npraynum"));
				
				retlist.add(retitem);
			}
			
		}
		return retlist;
	}
}
